package com.sjk.flink.kafka;

import org.apache.flink.streaming.connectors.kafka.KafkaSerializationSchema;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.jetbrains.annotations.Nullable;

public class CustomKafkaExprieSchema implements KafkaSerializationSchema<ConsumerRecord<String, String>> {

        private String prefix;

        public CustomKafkaExprieSchema(String prefix) {
                this.prefix = prefix;
        }

        @Override
        public ProducerRecord<byte[], byte[]> serialize(ConsumerRecord<String, String> stringStringConsumerRecord, @Nullable Long aLong) {
                String value = stringStringConsumerRecord.value();
                String topic = stringStringConsumerRecord.topic();
                String tableName = topic.substring(topic.indexOf("ODS_")+4).trim();
                String expireTopic = prefix+tableName;
                return new ProducerRecord<byte[], byte[]>(expireTopic, value.getBytes());
        }
}
